<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>收费系统</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
    <script type="text/javascript" src="../../script/jquery-1.10.2.min.js"></script>
    <style>
        .empty{ text-align: center; padding: 120px 0; }
    </style>
</head>
<body>
    <div class="container" id="container">
        <div id="divSearch" class="weui_cells weui_cells_form" style="margin-top:0px">
            <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">号牌号码</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input id="txtHPHM" class="weui_input" placeholder="请输入号牌号码"/>
            </div>
            </div>
        <div class="mainbutton">
            <a class="weui_btn weui_btn_primary" href="javascript:;" id="btnSearch" onclick="SearchVehicle()"  > 搜 索 </a>            
        </div>
        <br>
        <div class="mainbutton">
            <a class="weui_btn weui_btn_primary" href="javascript:;" id="btnTJ" onclick="TJSFInfo()"  > 当 天 统 计</a>            
        </div>
        <br>
        <div class="mainbutton">
            <a class="weui_btn weui_btn_primary" href="javascript:;" id="btnAdd" onclick="AddSFInfo()"  > 添 加 收 费</a>            
        </div>
        <div id="divListHeader" class="weui_cells_title">预收费车辆列表</div>
        </div>
    </div> 
</body>
</html>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript">
    var UIListView;
    var dialogBox;
    apiready = function(){
        UIListView = api.require('UIListView');
        dialogBox = api.require('dialogBox');
        GetVehicleByHPHM("");
    };

    function AddSFInfo()
    {
        api.openWin({
                name: 'win_sfinfo',
                url: 'win_sfinfo.html ',
                reload: true,
        });
    }

    function TJSFInfo()
    {
        var vSFY = $api.getStorage('UserCHName');
        var vUrlRead = $api.getStorage('ServerUrlRead');
       
        api.ajax({
            url:vUrlRead + '/WcfServices/GetSFTJBySFY/'+vSFY,
            method: 'post',
            contentType: "application/json",
        }, function(ret, err) {
            if (ret.IsSuccess) {
                //alert(JSON.stringify(ret.Data));
                var vData = InitSFList(ret.Data);
                ShowSFTJ(vData);
            }
        });
    }

    function SearchVehicle()
    {
        var vHphm = $("#txtHPHM").val();
        var curData = GetVehicleByHPHM(vHphm);
        ShowList(curData);
    }

    function GetVehicleByHPHM(paraHphm)
    {
        var vUrlRead = $api.getStorage('ServerUrlRead');
        var vSearchUrl = "";
        if(paraHphm == "")
        {
            vSearchUrl = vUrlRead + '/WcfServices/GetAllYSF_VEHICLE_INFO';
        }
        else
        {
            vSearchUrl = vUrlRead + '/WcfServices/GetYSF_VEHICLE_INFOByHPHM/'+paraHphm;
        }

        api.ajax({
            url:vSearchUrl,
            method: 'post',
            contentType: "application/json",
        }, function(ret, err) {
            if (ret.IsSuccess) {
                var vData = InitVehicleList(ret.Data);
                ShowList(vData);
            }
        });
    }

    function InitVehicleList(data)
    {
        if(data.length != 0)
        {
            var vData = new Array([data.length]);
            for (i = 0; i < data.length; i++) {
                var vSFSF = "";
                if(data[i].SFSF == "1" )
                {
                    vSFSF = "已收费";
                }
                else
                {
                    vSFSF = "未收费";
                }

                vData[i] = {
                    uid: data[i].ID,
                    title: data[i].HPHM + " " + data[i].HPZL,
                    subTitle: "金额：预[" + data[i].Y_SFJE + "] [" + data[i].WJY + "]",
                    remark:  data[i].WJSJ + " " +  vSFSF + " " +  data[i].S_SFJE
                }
            }
            return vData;
        }
        else
        {
            return null;
        }
    }

    function ShowList(vData)
    {
        var vHeight = $("#divSearch").height();
        var vListHeight =api.frameHeight - vHeight;
        UIListView.open({
                rect: {
                    x: 0,
                    y: vHeight,
                    w: api.winWidth,
                    h: vListHeight
                },
                data: vData,
                rightBtns: [
                {
                    bgColor: '#388e8e',
                    activeBgColor: '',
                    width: 70,
                    title: '删除',
                    titleSize: 12,
                    titleColor: '#fff',
                    icon: '',
                    iconWidth: 20
                },
                {
                    bgColor: '#388e8e',
                    activeBgColor: '',
                    width: 70,
                    title: '查看',
                    titleSize: 12,
                    titleColor: '#fff',
                    icon: '',
                    iconWidth: 20
                }],
                styles: {
                    borderColor: '#696969',
                    item: {
                        bgColor: '#AFEEEE',
                        activeBgColor: '#F5F5F5',
                        height: 55.0,
                        imgWidth: 40,
                        imgHeight: 40,
                        imgCorner: 4,
                        placeholderImg: '',
                        titleSize: 12.0,
                        titleColor: '#000',
                        subTitleSize: 12.0,
                        subTitleColor: '#000',
                        remarkColor: '#000',
                        remarkSize: 12,
                        remarkIconWidth: 30
                    }
                },
                fixedOn: api.frameName
            }, function(ret, err) {
                if(ret.eventType == "clickRightBtn")
                {
                    if(ret.btnIndex == 0)
                    {//删除收费
                        DeleteVehicle(vData[ret.index].uid);
                    }  

                    if(ret.btnIndex == 1)
                    {//查看详情
                        ViewVehicleAll(vData[ret.index].uid);
                    }                 
                }

                UIListView.setRefreshHeader({
                    bgColor: '#F5F5F5',
                    textColor: '#8E8E8E',
                    textDown: '下拉可以刷新...',
                    textUp: '松开开始刷新...',
                    showTime: true
                }, function(ret, err) {
                    if (ret) {
                        GetVehicleByHPHM("");
                    } else {
                    }
                });

            });
    }

    function InitVehicleInfoList(data)
    {
        if(data.length != 0)
        {
            var vSFSF = "";
            if(data.SFSF == "1" )
            {
                vSFSF = "已收费";
            }
            else
            {
                vSFSF = "未收费";
            }

            var vData = new Array([12]);
            vData[0] = { text: "号牌号码：" + data.HPHM};
            vData[1] = { text: "号牌种类：" + data.HPZL};
            vData[2] = { text: "累计行驶里程：" + data.LJXSLC};
            vData[3] = { text: "预收费代号：" + data.Y_SFDH};
            vData[4] = { text: "预收费金额：" + data.Y_SFJE};
            vData[5] = { text: "预收费人员：" + data.WJY};
            vData[6] = { text: "预收费时间：" + data.WJSJ};
            vData[7] = { text: "客户归属：" + data.SSKH};
            vData[8] = { text: "收费金额：" + data.S_SFJE};
            vData[9] = { text: "收费人员：" + data.SFY};
            vData[10] = { text: "收费时间：" + data.SFSJ};
            vData[11] = { text: "是否收费：" + vSFSF};

            return vData;
        }
        else
        {
            return null;
        }

    }

    //查看车辆详情
    function ViewVehicleAll(strId)
    {
        var vUrlWrite = $api.getStorage('ServerUrlWrite');
        api.ajax({
            url:vUrlWrite + '/YSFSysServices/GetYSF_VEHICLE_INFOByKey/'+strId,
            method: 'post',
            contentType: "application/json",
        }, function(ret, err) {
            if (ret.IsSuccess) {
                var vData = InitVehicleInfoList(ret.Data);
                ShowVehicleInfoList(vData);
            }
        });
    }

        //删除车辆收费信息
    function DeleteVehicle(strId)
    {
         api.confirm({
                title: '提示',
                msg: '是否要进行删除？',
                buttons: ['是', '否']
                }, function(ret, err) {
                    if( ret.buttonIndex == 1)
                    {
                        var vUrlWrite = $api.getStorage('ServerUrlWrite');
                        var vSFY = $api.getStorage('UserCHName');
                        api.ajax({
                            url:vUrlWrite + '/YSFSysServices/DeleteVEHICLE_INFO/'+strId + '/' + vSFY,
                            method: 'post',
                            contentType: "application/json",
                        }, function(ret, err) {
                            if (ret.IsSuccess) {
                                GetVehicleByHPHM("");
                            }
                        });
                    }
                });
    }

    function ShowVehicleInfoList(data)
    {
        dialogBox.scene({
            rect: {
                w: 320,
                h: 400
            },
            texts: {
                title: '收费详情',
                content: '',
                okBtnTitle: '关闭'
            },
            styles: {
                bg: '#fff',
                title: {
                    bg: '#aaa',
                    h: 44,
                    size: 14,
                    color: '#000'
                },
                sceneImg: {
                    h: 150,
                    path: 'widget://image/sceneImg.png'
                },
                content: {
                    color: '#111',
                    size: 12
                },
                cell: {
                    bg: '#fff',
                    h: 48,
                    text: {
                        color: '#636363',
                        size: 13
                    },
                    icon: {
                        marginL: 15,
                        marginT: 9,
                        w: 30,
                        h: 30,
                        corner: 2
                    }
                },
                ok: {
                    bg: '#89a',
                    titleColor: '#f00',
                     h: 48,
                     size: 16
                }
            },
            optionDatas: data
        }, function(ret, err) {
            if (ret) 
            {
                if(ret.eventType == "ok")
                {
                    dialogBox.close();
                }
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

      function ShowSFTJ(data)
    {
        dialogBox.scene({
            rect: {
                w: 320,
                h: 240
            },
            texts: {
                title: '收费统计',
                content: '',
                okBtnTitle: '关闭'
            },
            styles: {
                bg: '#fff',
                title: {
                    bg: '#aaa',
                    h: 44,
                    size: 14,
                    color: '#000'
                },
                sceneImg: {
                    h: 150,
                    path: 'widget://image/sceneImg.png'
                },
                content: {
                    color: '#111',
                    size: 12
                },
                cell: {
                    bg: '#fff',
                    h: 48,
                    text: {
                        color: '#636363',
                        size: 13
                    },
                    icon: {
                        marginL: 15,
                        marginT: 9,
                        w: 30,
                        h: 30,
                        corner: 2
                    }
                },
                ok: {
                    bg: '#89a',
                    titleColor: '#f00',
                     h: 48,
                     size: 16
                }
            },
            optionDatas: data
        }, function(ret, err) {
            if (ret) 
            {
                if(ret.eventType == "ok")
                {
                    dialogBox.close();
                }
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

    function InitSFList(data)
    {
        if(data.length != 0)
        {
            var vData = new Array([data.length]);
            for (var i = 0; i < data.length; i++) {
                 vData[i] = { text: data[i][0] +":" +  data[i][1]};
            }

            return vData;
        }
        else
        {
            return null;
        }

    }
</script>